package com.ninong.ker.admin.rest;

import com.alibaba.fastjson.JSONObject;
import com.ninong.ker.admin.service.FwGroupDataService;
import com.ninong.ker.admin.service.dto.FwGroupDataDTO;
import com.ninong.ker.common.tools.Constants;
import com.ninong.ker.common.tools.enums.BusinessEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import com.ninong.ker.common.annotation.log.Log;
import com.ninong.ker.common.annotation.perm.CmdAdmin;
import com.ninong.ker.common.response.CmdResponse;


/**
 * 组合数据详情表
 *
 * @author 鸠摩智
 * @email 123@qq.com
 * @date 2021-02-08 15:01:08
 */
@RestController
@RequestMapping("/cmd/v1/fwgroupdata")
public class FwGroupDataResouces {

    @Autowired
    private FwGroupDataService fwGroupDataService;

    /**
     * 列表
     */
    @Log("xx列表")
    @CmdAdmin({"admin", "formdata:data"})
    @PostMapping
    public ResponseEntity<CmdResponse> list(@RequestBody FwGroupDataDTO dto, @RequestHeader(value = Constants.TOKEN) String token) {
        CmdResponse response = new CmdResponse();
        response.setData(fwGroupDataService.listPage(dto,token));
        return ResponseEntity.ok(response);
    }

    @CmdAdmin({"admin", "formdata:data", "formdata:data"})
    @PutMapping
    public ResponseEntity<CmdResponse> create(@RequestBody JSONObject dto, @RequestHeader(value = Constants.TOKEN) String token) throws Exception {
        fwGroupDataService.create(dto, token);
        return ResponseEntity.ok(new CmdResponse());
    }

    @CmdAdmin({"admin", "formdata:data"})
    @GetMapping(value = "/{id}")
    public ResponseEntity<CmdResponse> get(@PathVariable String id) {
        CmdResponse response = new CmdResponse();
        response.setData(fwGroupDataService.get(id));
        return ResponseEntity.ok(response);
    }

}
